import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: BadgeFlexibleDemo(),
    );
  }
}

class BadgeFlexibleDemo extends StatelessWidget {
  const BadgeFlexibleDemo({super.key});

  @override
  Widget build(BuildContext context) {
    // 示例文字，可以变化长度
    final badgeText = "剩余7天";

    return Scaffold(
      body: Center(
        child: Stack(
          clipBehavior: Clip.none,
          children: [
            // 主体 Widget
            Container(
              width: 100,
              height: 100,
              color: Colors.grey[400],
            ),
            // 角标
            Positioned(
              top: 0,
              right: 0,
              child: Container(
                padding:
                const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
                decoration: BoxDecoration(
                  color: Colors.red,
                  borderRadius: BorderRadius.circular(12),
                ),
                child: Text(
                  badgeText,
                  style: const TextStyle(
                      color: Colors.white, fontSize: 12),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
